<html>
<head>
	<title>XaBook Installation</title>
	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
	<style type="text/css">
		body {
			background-color:white;
			font-family:"Trebuchet MS", verdana, sans-serif;
			font-size:12px;
		}
		
		input {
			font-family:verdana, sans-serif;
			font-size:12px;
		}
	</style>
</head>
<body>
<h2>XaBook Installation</h2>
Before you start installing, please make a empty file called mysql.config.php, and make it writable.
<br />There will automatically be created a account called "admin" (without "") with the password "admin" (again without "").
<br />
Remember to change the password.
<br /><br />
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<table>
	<tr>
		<td>MySQL Hostname:</td>
	</tr>
	<tr>
		<td><input type="text" name="hostname" value="localhost" /> (In most cases, the hostname is localhost)</td>
	</tr>
	<tr>
		<td>MySQL Username:</td>
	</tr>
	<tr>
		<td><input type="text" name="username" /></td>
	</tr>
	<tr>
		<td>MySQL Password:</td>
	</tr>
	<tr>
		<td><input type="password" name="password" /></td>
	</tr>
	<tr>
		<td>MySQL Database:</td>
	</tr>
	<tr>
		<td><input type="text" name="database" /> (Attempt to create, if not exist)</td>
	</tr>
	<tr>
		<td>Table prefix:</td>
	</tr>
	<tr>
		<td><input type="text" name="prefix" value="xabook_" /></td>
	</tr>
	<tr>
		<td><input type="submit" name="sub" value="Install" /></td>
	</tr>
</table>
</form>
<?php
if(isset($_POST['sub'])) {
	$hostname = $_POST['hostname'];
	$username = $_POST['username'];
	$password = $_POST['password'];
	$database = $_POST['database'];
	$prefix = $_POST['prefix'];
	
	if(!is_writable("mysql.config.php")) {
		echo "mysql.config.php is not writable!";
		exit;
	}
	
	$conn = @mysql_connect($hostname, $username, $password) or die(mysql_error());
	print $err;
	@mysql_query("create database if not exists " . $database) or die(mysql_error());
	@mysql_select_db($database) or die(mysql_error());
	
	// Create contacts table
	$sql = "
CREATE TABLE IF NOT EXISTS `" . $prefix . "contacts` (
  `id` int(11) NOT NULL auto_increment,
  `f_name` varchar(15) default NULL,
  `l_name` varchar(15) default NULL,
  `nick` varchar(15) default NULL,
  `address` varchar(50) default NULL,
  `zipcode` varchar(15) default NULL,
  `city` varchar(50) default NULL,
  `country` varchar(15) default NULL,
`private` varchar(5) default NULL,
`owner` varchar(11) default NULL,
  `web` varchar(50) default NULL,
  `mail` varchar(50) default NULL,
  `icq` int(11) NOT NULL default '0',
  `msn` varchar(50) default NULL,
  `ym` varchar(50) default NULL,
  `ph_home` varchar(50) default NULL,
  `ph_work` varchar(50) default NULL,
  `ph_mobile` varchar(50) default NULL,
  `comments` text NOT NULL,
  `user_group` varchar(15) default NULL,
  `state` varchar(50) NOT NULL default '',
  `day` int(11) NOT NULL default '0',
  `month` varchar(15) NOT NULL default '',
  `year` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM
	";

	// Create groups table
	$sql2 = "
CREATE TABLE IF NOT EXISTS `" . $prefix . "groups` (
  `id` int(11) NOT NULL auto_increment,
  `group_name` varchar(15) default NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM
	";

	// Make admin group
	$sql3 = "INSERT INTO `" . $prefix . "groups` VALUES (1, 'admin')";
	
	// Make users table
	$sql4 = "
CREATE TABLE IF NOT EXISTS `" . $prefix . "users` (
  `id` int(11) NOT NULL auto_increment,
  `uname` varchar(15) default NULL,
  `pword` text NOT NULL,
  `priv` varchar(15) default NULL,
  `user_group` varchar(50) NOT NULL default '',
`pin` varchar(15) default NULL,
`tel` varchar(15) default NULL,

  PRIMARY KEY  (`id`)
) TYPE=MyISAM
	";
	// Make admin user
	$sql5 = "INSERT INTO `" . $prefix . "users` VALUES (1, 'admin', '21232f297a57a5a743894a0e4a801fc3', '3', 'admin','100','100')";

	// Let's make the tables
	mysql_query($sql) or die(mysql_error());
	mysql_query($sql2) or die(mysql_error());
	mysql_query($sql3) or print(mysql_error() . "<br />");
	mysql_query($sql4) or die(mysql_error());
	mysql_query($sql5) or print(mysql_error() . "<br />");

	echo "Everything seems to be fine so far... I will now write out the config<br />";
	flush();
	sleep(2);
	if(!$f = @fopen("mysql.config.php", "w")) {
		echo "Unable to make config file!";
		exit;
	}

$data = "<?php
define(\"DB_NAME\", \"" . $database . "\");		// MySQL Database name
define(\"DB_USER\", \"" . $username . "\");		// MySQL Username
define(\"DB_PASSWORD\", \"" . $password . "\");	// MySQL Password
define(\"DB_HOST\", \"" . $hostname . "\");		// MySQL Host
define(\"DB_PREFIX\", \"" . $prefix . "\");		// Table Prefix
?>";
	
	if(!@fwrite($f, $data)) {
		echo "Cannot write to file!";
		exit;
	}
	
	@fclose($f);

	echo "Done!<br />";
	echo "Please remove install.php now";
		
}
	
?>
</body>
</html>
